# problem 12
from math import *
import time

divgoal = 500
testnum = 1

triangle = lambda n: (n * (n + 1)) / 2

def numDivisors(n):
    divcount = 0
    for canidate in xrange(1,ceil(sqrt(n))):
        if n % canidate == 0:
            divcount += 2
    if sqrt(n) % 1 == 0:
        divcount += 1
    return divcount

timeout = 20 + time.clock()

tribase = 0
high = 0
while time.clock() < timeout and high < divgoal:
    tribase += 1
    numdiv = numDivisors(triangle(tribase))
    if numdiv > high:
        high = numdiv
        print 'New high; triangle number %i (value of %i) has %i divisors.' % \
              (tribase, triangle(tribase), high)
